Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): support explain format json #19041

Merged
merged 14 commits into from
Oct 22, 2024
Merged

Conversation

kwannoel
Copy link
Contributor

@kwannoel kwannoel commented Oct 21, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Closes #18816 #17218 #14168

We just use the Pretty IR, wrap it in a newtype, derive a serde instance for it.

We intentionally do NOT use serde already implemented for the proto output of the to_proto phase (i.e. when to_stream_prost / to_batch_prost are called). That's because it locks the plan type to the stream_proto / batch_proto type.

EXPLAIN FORMAT JSON should only change the format, and not determine the underlying plan type (logical / stream / batch / to_proto).

Explain terse doesn't need to be supported. Using the json output, we can just do (see before/after below):

 jq 'def extract: {name: .name, children: [.children[] | extract]}; extract' plan.json
before
    {
      "name": "LogicalProject",
      "fields": {
        "exprs": [
          "approx_percentile($expr1)"
        ]
      },
      "children": [
        {
          "name": "LogicalAgg",
          "fields": {
            "aggs": [
              "approx_percentile($expr1)"
            ]
          },
          "children": [
            {
              "name": "LogicalProject",
              "fields": {
                "exprs": [
                  "t.v1::Float64 as $expr1"
                ]
              },
              "children": [
                {
                  "name": "LogicalScan",
                  "fields": {
                    "columns": [
                      "t.v1",
                      "t._row_id"
                    ],
                    "table": "t"
                  },
                  "children": []
                }
              ]
            }
          ]
        }
      ]
    }
after
{
  "name": "LogicalProject",
  "children": [
    {
      "name": "LogicalAgg",
      "children": [
        {
          "name": "LogicalProject",
          "children": [
            {
              "name": "LogicalScan",
              "children": []
            }
          ]
        }
      ]
    }
  ]
}

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

Public Preview: Do note that the structure and format of EXPLAIN FORMAT JSON is considered unstable, and may change overtime.

After this PR, a new explain option is supported

FORMAT (TEXT | JSON)

For FORMAT JSON, it will output json for logical and physical plans, while it ignores trace, distsql options.
For FORMAT TEXT, the output is the same as the current output format of explain.

Here's an example:

create table t(v1 int);
explain(physical, format json) create materialized view m1 as select * from t;
  {
   "name": "StreamMaterialize",
   "fields": {
     "columns": [
       "v1",
       "t._row_id(hidden)"
     ],
     "pk_columns": [
       "t._row_id"
     ],
     "pk_conflict": "NoCheck",
     "stream_key": [
       "t._row_id"
     ]
   },
   "children": [
     {
       "name": "StreamTableScan",
       "fields": {
         "columns": [
           "v1",
           "_row_id"
         ],
         "table": "t"
       },
       "children": []
     }
   ]
 }

@kwannoel kwannoel changed the title Kwannoel/structured explain feat(frontend): support json structured explain Oct 22, 2024
@kwannoel kwannoel changed the title feat(frontend): support json structured explain feat(frontend): support explain format json Oct 22, 2024
@kwannoel kwannoel marked this pull request as ready for review October 22, 2024 04:04
@kwannoel kwannoel requested review from xxchan and st1page and removed request for BugenZhao October 22, 2024 06:33
@kwannoel kwannoel force-pushed the kwannoel/structured-explain branch from 7a18ef4 to 0ece979 Compare October 22, 2024 06:38
@xxchan
Copy link
Member

xxchan commented Oct 22, 2024

QQ: Is this just for debugging and not ready to be used widely by users? I assume the format is not finalized and will be subject to change. (If so we can happily merge and try it quickly)

@kwannoel
Copy link
Contributor Author

QQ: Is this just for debugging and not ready to be used widely by users? I assume the format is not finalized and will be subject to change. (If so we can happily merge and try it quickly)

Yeah it's mainly for us to get a structured output of the users query plan.

Copy link
Member

@xxchan xxchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally LGTM

(But did not read / play with the format. If it's not finalized, I think we can play with it and refine it as needed

@xxchan
Copy link
Member

xxchan commented Oct 22, 2024

Do we want to document it now? If yes, we should note format stability

@kwannoel kwannoel force-pushed the kwannoel/structured-explain branch from 0ece979 to babdbb1 Compare October 22, 2024 08:22
@kwannoel kwannoel force-pushed the kwannoel/structured-explain branch from 12e47c7 to 36af875 Compare October 22, 2024 08:28
e2e_test/batch/explain.slt Outdated Show resolved Hide resolved
@kwannoel kwannoel requested a review from xxchan October 22, 2024 08:30
@kwannoel kwannoel enabled auto-merge October 22, 2024 10:18
@kwannoel kwannoel added this pull request to the merge queue Oct 22, 2024
Merged via the queue into main with commit 5ca0a73 Oct 22, 2024
29 of 30 checks passed
@kwannoel kwannoel deleted the kwannoel/structured-explain branch October 22, 2024 12:54
@kwannoel kwannoel added the user-facing-changes Contains changes that are visible to users label Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature user-facing-changes Contains changes that are visible to users
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking: Improve explain's output for large plan-node DAGs
3 participants